package com.coocaa.internship.dao;
import com.coocaa.internship.pojo.PositionInfo;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 职位信息Dao层
 * @Author: zwh
 * @Date: 2019-07-26
 * @Time: 1:04
 */
@Mapper
@Component
public interface PositionInfoDao {
    String TABLE_NAME = "position_info";

    String SELECT_FILEDS = "position_id , position_name , position_label , company_id " +
            ",position_area , position_duration , position_salary , position_require , position_duty , publish_time, position_type";

    String INSERT_FILEDS = "position_name , position_label , company_id , position_area , position_duration " +
            ", position_salary , position_require , position_duty, position_type";

    @Select({"select ", SELECT_FILEDS, " from ", TABLE_NAME, " where position_id = #{positionId}"})
    PositionInfo selectPositionInfoById(@Param("positionId") Long positionId);

    @Select({"select ", SELECT_FILEDS, " from ", TABLE_NAME, " where position_name like '%${positionName}%'"})
    List<PositionInfo> selectPositionInfoByName(@Param("positionName") String positionName);

    @Insert({"insert into ", TABLE_NAME, " (", INSERT_FILEDS, ") values (#{positionName} , #{positionLabel}, #{companyId}" +
            ", #{positionArea}, #{positionDuration}, #{positionSalary}, #{positionRequire}, #{positionDuty}, #{positionType})"})
    Integer insertPostitionInfo(PositionInfo positionInfo);

    @Select({"select", SELECT_FILEDS, "from", TABLE_NAME})
    ArrayList<PositionInfo> selectAll();

    @Delete({"delete from ", TABLE_NAME, "where position_id=#{positionId}"})
    Integer deleteByPositionId(Long positionId);

    @Delete({"delete from ", TABLE_NAME, "where position_name=#{positionName}"})
    Integer deleteByPositionName(String positionName);


    Integer updateByPositionId(PositionInfo positionInfo);

    @Select({"select * from ", TABLE_NAME, " where company_id=#{companyId}"})
    List<PositionInfo> selectByCompanyId(Long companyId);
}
